#include "setting.h"
#include <QDebug>
#include <QSettings>
#include <QStandardPaths>
#include <QMessageBox>
#include <QErrorMessage>
#include <QApplication>
#include <QGraphicsEffect>
#include "unistd.h"
#include "customstyle.h"
#include "util/xatom-helper.h"

Setting::Setting(QWidget *parent)
  : QFrame(parent)
{

    MotifWmHints hints;
    hints.flags = MWM_HINTS_FUNCTIONS|MWM_HINTS_DECORATIONS;
    hints.functions = MWM_FUNC_ALL;
    hints.decorations = MWM_DECOR_BORDER;
    XAtomHelper::getInstance()->setWindowMotifHint(this->winId(), hints);
    init_ui();
    this->setForegroundRole(QPalette::Highlight);
    this->setAutoFillBackground(true);
    this->setStyleSheet("QWidget#widgetMain{border: 1px solid #FF00FF; border-radius: 5px;}");
    QGraphicsEffect *effect = nullptr;
    this->setFrameStyle(QFrame::Panel);
//    this->setFixedWidth(80);
//    effect->sourceChanged(QGraphicsEffect::SourceInvalidated);
    this->setGraphicsEffect(effect);
//    connect(help,&QPushButton::clicked,this,&Setting::initHelp);
}


void Setting::init_ui(){
//    this->setAttribute(Qt::WA_StyledBackground);
//    this->setAttribute(Qt::WA_TranslucentBackground, false);//窗体透明
    menu = new QMenu;
//    mirror_action = new QWidgetAction(this);
    delay_action = new QWidgetAction(this);
//    mirrorlab = new QLabel;
    delaylab = new QLabel;

    delay = new QWidget;
//    mirror = new QWidget;
    delaylab->setText(tr("Delayed"));
//    mirrorlab->setText(tr("mirroring"));
    set = new QAction(tr("set"),menu);
    theme = new QAction(tr("theme"),menu);
    help = new QAction(tr("help"),menu);
    about = new QAction(tr("about"),menu);
    quit = new QAction(tr("quit"),menu);
//    mirrorbtn = new SwitchButton(this);
    delaybtn = new SwitchButton(this);
    themeMenu = new QMenu;

    delayLayout = new QHBoxLayout;
//    mirrorLayout = new QHBoxLayout;
    delay->setFixedHeight(30);
//    mirror->setFixedHeight(30);
    menu->setCursor(Qt::PointingHandCursor);

    QString btnStyle = \
        "opacity: 1;"
        "border-radius: 4px;";

    QString labStyle = \
        "font-size: 14px;"
        "line-height: 32px;"
        "opacity: 1;";

    //设置按钮布局
    delayLayout->addSpacing(12);
    delayLayout->addWidget(delaylab);
    delayLayout->addStretch(5);
    delayLayout->addWidget(delaybtn);
    delayLayout->addSpacing(10);
    delayLayout->setMargin(0);
    delay->setLayout(delayLayout);
    delay_action->setDefaultWidget(delay);

    menu->addAction(set);
    menu->addAction(help);
    menu->addAction(about);
    menu->addAction(quit);

    QActionGroup *themeMenuGroup = new QActionGroup(this);
    QAction *autoTheme = new QAction(tr("Auto"),this);
    themeMenuGroup->addAction(autoTheme);
    themeMenu->addAction(autoTheme);
    autoTheme->setCheckable(true);
    QAction *lightTheme = new QAction(tr("Light"),this);
    themeMenuGroup->addAction(lightTheme);
    themeMenu->addAction(lightTheme);
    lightTheme->setCheckable(true);
    QAction *darkTheme = new QAction(tr("Dark"),this);
    themeMenuGroup->addAction(darkTheme);
    themeMenu->addAction(darkTheme);
    darkTheme->setCheckable(true);
    QList<QAction* > themeActions;
    themeActions<<autoTheme<<lightTheme<<darkTheme;

}


